/**获取DOM节点
 * 
 * @param {String} Selector 
 */
function $(Selector) {
    // 异常处理
    if (typeof Selector !== 'string' || Selector === '' || /\s/.test(Selector)) {
        return null;
    }
    if (/^#/.test(Selector)) {
        return document.getElementById(Selector.slice(1));
    }
    if (/^\./.test(Selector)) {
        return document.getElementsByClassName(Selector.slice(1));
    }
    return document.getElementsByTagName(Selector);
}

function clickSelected(e) {
    e = event || window.event;
    var elem = e.target;
    var root = elem.parentElement.parentElement;
    var parents = root.children;
    for (var parent in parents) {
        parent.children[0].classList.remove("selected");
    }
    elem.classList.add("selected");
}

function toggleActived(e) {
    e = event || window.event;
    var elem = e.target;
    var previousSibling = elem.previousSibling;
    while (previousSibling && previousSibling.nodeType !== 1) {
        previousSibling = previousSibling.previousSibling;
    }
    previousSibling.classList.toggle("actived");
}

Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

Array.prototype.contains = function (needle) {
    for (i in this) {
        if (this[i] == needle) return true;
    }
    return false;
};

function toggleImg(e) {
    e = event || window.event;
    var elem = e.target;
    var image = elem.nodeName === "A" ? elem.children[0] : elem.parentElement.children[0];
    var url = image.src;
    if ((/_dian\.png$/).test(url)) {
        image.src = url.replace(/_dian/, "");
    } else {
        image.src = url.replace(/\.png$/, "_dian.png");
    }
}

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

function appId() {
    var appId = window.sessionStorage.getItem("appId");
    if (appId == null || appId == undefined || appId == '')
        return null;
    else
        return appId;
};